// https://leetcode.cn/problems/first-missing-positive/description/?envType=study-plan-v2&envId=top-100-liked

// 思路:仿照了hash表
class Solution {
public:
    int firstMissingPositive(vector<int>& nums) 
    {
        int n = nums.size();
        int flag = false;
        for(int i = 0; i < n; i++) {
            if(nums[i] == 1) {
                flag = true;
            }
        }
        if(!flag) {
            return 1;
        }
        for(int i = 0; i < n; i++) {
            if(nums[i] <= 0 || nums[i] > n) {
                nums[i] = 1;
            }
        }
        for(int i = 0; i < n; i++) {
            int t = abs(nums[i]) - 1;
            nums[t] = -abs(nums[t]);
        }
        for(int i = 0; i < n; i++) {
            if(nums[i] > 0) {
                return i + 1;
            }
        }
        return n + 1;
    }
};